//
//  Api.m
//  MyFrameWork
//
//  Created by eason on 16/4/25.
//  Copyright © 2016年 普惠. All rights reserved.
//

#import "Api.h"

static Api * instance = nil;

@implementation Api

+ (Api *)sharedInstance
{
    @synchronized (self)
    {
        if (instance == nil)
        {
            instance = [[self alloc] init];
        }
    }
    return instance;
}

+ (id) allocWithZone:(NSZone *)zone
{
    @synchronized (self) {
        if (instance == nil) {
            instance = [super allocWithZone:zone];
            return instance;
        }
    }
    return nil;
}

- (id) copyWithZone:(NSZone *)zone
{
    return self;
}

#pragma mark - Api URL

- (NSString *)networkURL
{
    if (IS_TEST) {
        return TEST_NETWORK_URL;
    }
    return REAL_NETWORK_URL;
}

- (NSString *)mediaURL
{
    if (IS_TEST) {
        return TEST_MEDIA_URL;
    }
    return REAL_MEDIA_URL;
}

#pragma mark 走进虎门

- (void)asyncHumenIntroduceWithSuccess:(void (^) (TestModel * bean))successblock WithErrorBlock:(ErrorBlock)errorBlock WithFailureBlock:(FailureBlock)failureBlock
{
    ApiRequest * request = [[ApiRequest alloc] init];
    [request addMethod:@"getHumenIntroduction"];
    
    [NetRequestClass NetRequestPOSTWithRequestURL:[self networkURL] WithParameter:[request requestParam] WithReturnValueBlock:^(ApiResponse * response, id returnValue) {
        [response resolveResponse:[TestModel new]];
        successblock(response.responseObj);
    } WithErrorCodeBlock:errorBlock WithFailureBlock:failureBlock];
}

@end
